<?php session_start(); 
if($logout != NULL AND $logout == "yes"){
$_SESSION['isLoggedIn'] = "no";}
if($_SESSION['isLoggedIn'] == "logged"){
header('Location: header.php');}
?>

<?php //doing login validation

		
		if(isset($_POST['id']) AND isset($_POST['pass']))
		{
			$host = 'localhost';
			$username = 'medic_site';
			$password = 'm3dicsit3';
			$database = 'medic_site';
			$incomingID = mysql_real_escape_string($_POST['id']);
			$incomingPass = mysql_real_escape_string($_POST['pass']);
	
			$login = false;
			$db = mysql_connect($host, $username, $password);
			mysql_select_db($database, $db);
			
			$sql = "select * from admin where id = '$incomingID'";
			$query = mysql_query($sql, $db);
		
			while($data = mysql_fetch_row($query)) {
				if($data[1] == $incomingPass){
					$login = true;
				}
			}
			mysql_free_result($query);  
			
			if($login ==  true)
			{
				
				$_SESSION['isLoggedIn'] = "logged";
				$_SESSION['lg'] = $_POST['lang'];
				header('Location: header.php?source=home&lg=' . $_POST["lang"]);
				
			}
			else
			{
				$invalid = 1;
			}
		}
		else
		{
		
		}
		
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Admin - Log In</title>

</head>

<body>

<div style="width:100%; height:40px; background-color:#FFFFFF; z-index:1;"><img src="mipsmedia2.jpg" style="float:left; padding-top:5px;" height="40"/></div>

<div style="position:relative; top:100px; left:250px; border:1px solid #CCCCCC; padding:100px 100px 100px 100px; width:325px; height:125px;">

<div style="position:absolute; left:15px; top:5px;"><h2 style="color:#1b5faa; font-family:'Myriad Pro', sans-serif, helvetica;">Administration Login</h2>
</div>

<div style="position:absolute; top:75px; left:10px; padding:0px 10px 10px 10px; width:200px; font-family:'Myriad Pro', sans-serif, helvetica; color:#999999; font-size:13px; font-weight:bold;">Use a valid username and password to gain access to the Administrator Back-end.
</div>

<div style="position:absolute; top:75px; right:15px; padding:10px 10px 0px 10px; border:1px solid #CCCCCC;">
<form action="index.php" method="post" name="login">
<table cellpadding="0" cellspacing="10" border="0">
<?php if($invalid == 1) { ?> <tr><td colspan="2"><div style="font-family:'Myriad Pro', sans-serif, helvetica; color:red; font-size:13px; font-weight:bold;">Invalid credentials. Please try again.</div></td></tr> <?php } ?>
<tr><td><div style="font-family:'Myriad Pro', sans-serif, helvetica; color:#666666; font-size:13px; font-weight:bold;">Username</div></td><td><input type="text" name="id" value="" /></td></tr>
<tr><td><div style="font-family:'Myriad Pro', sans-serif, helvetica; color:#666666; font-size:13px; font-weight:bold;">Password</div></td><td><input type="password" name="pass" value="" /></td></tr>
<tr><td><div style="font-family:'Myriad Pro', sans-serif, helvetica; color:#666666; font-size:13px; font-weight:bold;">Language</div></td><td><select name="lang" style="width:145px;"><option value="fr" selected>Fran&ccedil;ais</option><option value="en">English</option></select></td></tr>
<tr><td></td><td valign="middle"><div align="right"><div style="height:26px; background-image:url(login_left.png); margin-left:70px; cursor:pointer;" onclick="login.submit();"><span style="vertical-align:super;font-family:'Myriad Pro', sans-serif, helvetica; color:#666666; font-weight:bold;">Login  </span><img src="login_right.png" /></div></div></td></tr></table></form>
</div>

<div style="position:absolute; float:left; left:10px; top:150px; padding:0px 10px 10px 10px; width:200px;"><img src="lock.png" /></div>

</div>				

</body>
</html>